# -*- coding: cp1252 -*-
import MySQLdb as mdb
import sys

class ConnectDB:
    def __init__(self, host = 'localhost', user = 'root', pw = '3213', db = 'controledb'):
        self.host = host
        self.user = user
        self.pw = pw
        self.db = db

    def ComandoRetorno(self, comando):
        try:
            
            conn = mdb.connect(self.host, self.user, self.pw, self.db)
            
            cursor = conn.cursor()
            cursor.execute(comando)
            dados = cursor.fetchall()
            
            conn.commit()
            
            cursor.close()
            return dados
        
        except mdb.Error, e:
            print "Error %d: %s" % (e.args[0],e.args[1])
            return False


    def Comando(self, comando):
        
        try:
            
            conn = mdb.connect(self.host, self.user, self.pw, self.db)
            
            cursor = conn.cursor()
            cursor.execute(comando)
            conn.commit()
            
            cursor.close()
            return True
        
        except mdb.Error, e:
            print "Error %d: %s" % (e.args[0],e.args[1])
            return False


